import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
import Blog from '../views/Blog.vue'
import Video from '../views/Video.vue'
import Login from '../views/Login.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: '首页',
    component: Home
  },
  {
    path:'/blog',
    name:'博客',
    component:Blog
  },
  {
    path:'/video',
    name:'视频',
    component:Video
  },
  {
    path:'/login',
    name:'登录',
    component:Login
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

// 导航守卫
// 如果点击的不是登录页，且处于未登录的状态，那么跳转登录页，阻止进入其他页面
// 如果点击的是登录页，那么不反应
// 如果点击的不是登录页，且处于登录状态，那么正常访问
// router.beforeEach((to,from,next)=>{
//   if(to.path !== "/login"){
//     if(localStorage.getItem('usr')){
//       next();
//     }else{
//       next("/login");
//     }
//   }else{
//     next();
//   }
// })

export default router
